﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ThreeByte.ActiveDeck.Config;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using ThreeByte.ActiveDeck.Content;

namespace ThreeByte.ActiveDeck.Controls
{
    /// <summary>
    /// Interaction logic for UserSlideConfiguration.xaml
    /// </summary>
    public partial class UserSlideConfiguration : UserControl
    {

        private UserSlideConfig _mConfig;

        public UserSlideConfiguration(PageConfig config) {
            InitializeComponent();

            _mConfig = (UserSlideConfig)config;
            DataContext = config;
        }

        private void PromptForNewImage() {
            System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
            fileDialog.CheckFileExists = true;
            System.Windows.Forms.DialogResult result = fileDialog.ShowDialog();
            if (result != System.Windows.Forms.DialogResult.OK) {
                return;
            }

            string filePath = fileDialog.FileName;
            string fileName = fileDialog.SafeFileName;

            _mConfig.Image = new GraphicResource(fileName, new Uri(filePath), ImageType.JPEG);//Store Backgrounds as JPEGS
            _mConfig.ScaleToFill = true;
        }

        private void SnapshotButton_Click(object sender, RoutedEventArgs e) {
            //Grab the current slide and store it here

            PowerPoint.Presentation currentPresentation = _mConfig.ParentSlideConfig.Parent.Presentation;
            BitmapImage image = SlideUtil.Snapshot(currentPresentation.Slides.FindBySlideID(_mConfig.ParentSlideConfig.SlideId));
            string imageName = string.Format("Snapshot_Slide{0:000}", _mConfig.ParentSlideConfig.SlideId);
            _mConfig.Image = new GraphicResource(image, imageName, ImageType.JPEG);
            _mConfig.ScaleToFill = false;
            _mConfig.LayoutOrientation = ThreeByte.ActiveDeck.Content.Orientation.LandscapeRight;
        }

        private void ChoosePictureButton_Click(object sender, RoutedEventArgs e) {
            PromptForNewImage();
        }

    }
}
